package com.tcode.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import com.tcode.bean.DeptBean;
import com.tcode.utils.JDBCUtil;

public class DeptDao {
	
	
	
	public List<DeptBean> searchAll() throws SQLException{
		List<DeptBean> list  = new ArrayList<DeptBean>();
		
		StringBuffer sql = new StringBuffer();
		
		sql.append("SELECT * FROM sys_dept_t ");
		
		Connection conn= JDBCUtil.getConection();
		
		PreparedStatement ps = conn.prepareStatement(sql.toString());
		
		ResultSet rs =ps.executeQuery();
		
		
		while(rs.next()) {
			DeptBean dept = new DeptBean();
			dept.setDeptid(rs.getInt(1));
			dept.setDeptName(rs.getString(2));
			dept.setManagerID(rs.getInt(3));
			dept.setCreatedate(rs.getString(4));
			list.add(dept);
			
		} 
		
		JDBCUtil.close(conn);
		
		return list;
	}

}
